/*************************************************************************
 * Copyright(C),2017,ZDC Corporation.
 * All right reserved.
 * 
 * File Name: chat.c
 * Description:
 * Author: mdc
 * Mail: 1436208384@qq.com
 * Created Time: 2017年09月15日 星期五 15时20分01秒
 ************************************************************************/
#include "chat.h"
int main(int argc,const char *argv[])
{
    pthread_t pid;
    int res;
    //MD5FileUpdateFile(&md5c,"你要测试的文件路径");  
    read_config();   //读取配置文件
    sleep(1);
    //根据不同连接方式创建服务端线程
    if (0 == strcmp(connect_cfg,"0"))
    {
        if (0 != (res = pthread_create(&pid,NULL,tcpserver,NULL)))
        {
            printf("Create thread failed\n");
            exit(res);
        }
    }
    else if (0 == strcmp(connect_cfg,"1"))
    {
        if (0 != (res = pthread_create(&pid,NULL,udpserver,NULL)))
        {
            printf("Create thread failed\n");
            exit(res);
        }
    }

    do 
    {
        ui_login(); //登录界面
        /*测试buf内容*/
        puts(name);
        puts(md5lgpwd);
        puts(name_cfg);
        puts(pwd_cfg);
        puts(ip_cfg);
        puts(port_cfg);
        puts(connect_cfg);
        /*测试结束*/
    }while (0 != strcmp(name,name_cfg) || (0 != strcmp(md5lgpwd,pwd_cfg)));//比较用户输入和配置文件
    chating();  //聊天界面
    //等待线程结束
    if (0 == (res = pthread_join(pid,NULL)))
    {
        printf("Thread joined\n");
    }
    return 0;
}
